# -*- coding: utf-8 -*-
import scrapy
from bilibili.items import BilibiliItem


class BilibiliSpiderSpider(scrapy.Spider):
    name = "bilibili_spider"
    allowed_domains = ["localhost:8899"]
    start_urls = ['http://localhost:8899/']
    # allowed_domains = ["bilibili.com/"]
    # start_urls = ['http://www.bilibili.com/']

    def parse(self, response):
        sub_selector = response.xpath('//div[@class="card-timing-module clearfix card-timing"]')
        items = []

        for sub in sub_selector:
            item = BilibiliItem()
            name = sub.xpath('.//div[@class="r-text"]/a/text()').extract()[0].encode('utf8')
            update = sub.xpath('.//div[@class="r-text"]/p/span/a/text()').extract()[0].encode('utf8')

            item['name'] = name
            item['update'] = update
            items.append(item)

            print '-------------print-----------'
            print name
            print update

        return items
